package com.weetop.aklyscan.presenter;

import android.app.Activity;

import com.blankj.utilcode.util.LogUtils;
import com.weetop.aklyscan.base.mvp.BaseModel;
import com.weetop.aklyscan.base.mvp.BaseObserver;
import com.weetop.aklyscan.base.mvp.BasePresenter;
import com.weetop.aklyscan.bean.FittingInfo;
import com.weetop.aklyscan.bean.MaterialInfoBean;
import com.weetop.aklyscan.bean.OnlineOutStockItemBean;
import com.weetop.aklyscan.bean.OutStockItemBean;
import com.weetop.aklyscan.bean.ProductDetailBean;
import com.weetop.aklyscan.bean.ProductInfo;
import com.weetop.aklyscan.bean.ScanChukuBean;
import com.weetop.aklyscan.bean.ScanGoodsCodeBean;
import com.weetop.aklyscan.bean.TransferBoxBean;
import com.weetop.aklyscan.bean.TypeInfo;
import com.weetop.aklyscan.bean.ZXGoodsInfo;
import com.weetop.aklyscan.view.ScanOutView;

import org.json.JSONArray;

import java.util.List;

public class ScanOutPresent extends BasePresenter<ScanOutView> {

    public ScanOutPresent(ScanOutView baseView, Activity activity) {
        super(baseView, activity);
    }

    /**
     * @param type_id  产品类型：1产品；2配件
     * @param order_sn 出库单编号
     */
    public void outStockDetail01(String type_id, String order_sn, final int b) {
        addDisposable(apiServer.getOutProductList(type_id, order_sn), new BaseObserver<BaseModel<List<ProductDetailBean>>>(baseView) {
            @Override
            public void onSuccess(BaseModel<List<ProductDetailBean>> o) {
                baseView.getOutStockDetail01Success(o, b);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.showError(msg);
                }
            }
        });
    }

    public void Into07(String matter_code) {
        addDisposable(apiServer.Into07(matter_code), new BaseObserver<BaseModel<FittingInfo>>(baseView) {
            @Override
            public void onSuccess(BaseModel<FittingInfo> o) {
                baseView.getInto07Success(matter_code, o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.showError(msg);
                }
            }
        });
    }

    /**
     * @param type_id  产品类型：1产品；2配件
     * @param order_sn 出库单编号
     */
    public void outStockDetail02(String type_id, String order_sn) {
//        addDisposable(apiServer.Out01(type_id, order_sn), new BaseObserver<BaseModel<List<FittingDetailBean>>>(baseView) {
//            @Override
//            public void onSuccess(BaseModel<List<FittingDetailBean>> o) {
//                baseView.getOutStockDetail02Success(o);
//            }
//
//            @Override
//            public void onError(String msg) {
//                if (baseView != null) {
//                    baseView.showError(msg);
//                }
//            }
//        });
    }

    public void scanBox(String code) {
        addDisposable(apiServer.scanTransferBox(code), new BaseObserver<BaseModel<TransferBoxBean>>(baseView) {
            @Override
            public void onSuccess(BaseModel<TransferBoxBean> o) {
                baseView.scanBoxSuccess(o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.showError(msg);
                }
            }
        });
    }

    // items: List<OutItemBean>
    public void outKuSave(String type_id, String order_sn, String items) {
////        String itemsString = GsonUtils.toJson(items);
//        addDisposable(apiServer.submitOutOrder(type_id, order_sn, items), new BaseObserver<BaseModel<Object>>(baseView) {
//            @Override
//            public void onSuccess(BaseModel<Object> o) {
//                baseView.saveOutKuSuccess(o);
//            }
//
//            @Override
//            public void onError(String msg) {
//                if (baseView != null) {
//                    baseView.showError(msg);
//                }
//            }
//        });
    }

    public void out8(String order_sn, JSONArray items) {
        LogUtils.d("items----" + items);
        addDisposable(apiServer.Out08(order_sn, items), new BaseObserver<BaseModel<String>>(baseView) {
            @Override
            public void onSuccess(BaseModel<String> o) {
                baseView.getOut08Success(o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.onUpFail(msg);
                }
            }
        });
    }

    public void scanFitting(String matter_code) {
        addDisposable(apiServer.Into07(matter_code), new BaseObserver<BaseModel<FittingInfo>>(baseView) {
            @Override
            public void onSuccess(BaseModel<FittingInfo> o) {
                baseView.getFittingInfoSuccess(matter_code, o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.showError(msg);
                }
            }
        });
    }


    public void scanProduct(String goods_sn) {
        addDisposable(apiServer.getProductInfo(goods_sn), new BaseObserver<BaseModel<ProductInfo>>(baseView) {
            @Override
            public void onSuccess(BaseModel<ProductInfo> o) {
                baseView.getProductInfSuccess(o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.showError(msg);
                }
            }
        });
    }

    /**
     * @param type 1产品序列号、2配件编号、3中转箱条码
     * @param code 扫码结果: 产品编码，配件编号，中转箱条码
     */
    public void scanHuoPinCode(String type, String code) {
        addDisposable(apiServer.scanGoodsCode(type, code), new BaseObserver<BaseModel<List<ScanGoodsCodeBean>>>(baseView) {
            @Override
            public void onSuccess(BaseModel<List<ScanGoodsCodeBean>> o) {
                baseView.getGoodsListSuccess(o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.showError(msg);
                }
            }
        });
    }


    public void Into10() {
        addDisposable(apiServer.Into10(), new BaseObserver<BaseModel<List<TypeInfo>>>(baseView) {
            @Override
            public void onSuccess(BaseModel<List<TypeInfo>> o) {
                baseView.getInto10Success(o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.showError(msg);
                }
            }
        });
    }

    public void Into11() {
        addDisposable(apiServer.Into11(), new BaseObserver<BaseModel<List<TypeInfo>>>(baseView) {
            @Override
            public void onSuccess(BaseModel<List<TypeInfo>> o) {
                baseView.getInto11Success(o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.showError(msg);
                }
            }
        });
    }

    public void Out01(String shop_type, String order_type, String order_sn) {
        addDisposable(apiServer.Out01(shop_type, order_sn, order_type), new BaseObserver<BaseModel<OutStockItemBean>>(baseView) {
            @Override
            public void onSuccess(BaseModel<OutStockItemBean> o) {
                baseView.getOut01Success(o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.showError(msg);
                }
            }
        });
    }

    public void details(String order_sn) {
        String address = "http://erp.auko.zjteam.com/public/cpxxxs/shop/details";
        addDisposable(apiServer.details(address, order_sn), new BaseObserver<BaseModel<OnlineOutStockItemBean>>(baseView) {
            @Override
            public void onSuccess(BaseModel<OnlineOutStockItemBean> o) {
                baseView.getDetailSuccess(o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.showError(msg);
                }
            }
        });
    }

    public void Into13(String code) {
        addDisposable(apiServer.Into13(code), new BaseObserver<BaseModel<Object>>(baseView) {
            @Override
            public void onSuccess(BaseModel<Object> o) {
                baseView.getInto13Success(o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.onDataError();
                }
            }
        });
    }

    public void saveZx(String barcode) {
        addDisposable(apiServer.into01(barcode), new BaseObserver<BaseModel<Object>>(baseView) {
            @Override
            public void onSuccess(BaseModel<Object> o) {
                baseView.saveZxSuccess(o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.onDataError();
                }
            }
        });
    }

    public void peiJianDetails(String order_sn) {
        String address = "http://erp.auko.zjteam.com/public/pjxs/shop/details";
        addDisposable(apiServer.peiJianDetails(address, order_sn), new BaseObserver<BaseModel<OnlineOutStockItemBean>>(baseView) {
            @Override
            public void onSuccess(BaseModel<OnlineOutStockItemBean> o) {
                baseView.getPeiJianDetailSuccess(o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.showError(msg);
                }
            }
        });
    }


    public void materialInfo(String action, String order_sn) {
        addDisposable(apiServer.materialInfo("http://erp.auko.zjteam.com/scs/product/material/info", action, order_sn), new BaseObserver<BaseModel<MaterialInfoBean>>(baseView) {
            @Override
            public void onSuccess(BaseModel<MaterialInfoBean> o) {
                baseView.getMaterialInfoSuccess(o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.showError(msg);
                }
            }
        });
    }

    public void Into08(String type, String serial_code, String order_sn) {
        addDisposable(apiServer.Into08(type, serial_code, order_sn), new BaseObserver<BaseModel<ZXGoodsInfo>>(baseView) {
            @Override
            public void onSuccess(BaseModel<ZXGoodsInfo> o) {
                baseView.getInto08Success(o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.showError(msg);
                }
            }
        });
    }

    public void Out03(String order_type, String order_sn, JSONArray items) {
        addDisposable(apiServer.Out03(order_type, order_sn, items), new BaseObserver<BaseModel<String>>(baseView) {
            @Override
            public void onSuccess(BaseModel<String> o) {
                baseView.getOut03Success(o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.showError(msg);
                }
            }
        });
    }

    public void Out07(String order_sn, JSONArray items) {
        addDisposable(apiServer.Out07(order_sn, items), new BaseObserver<BaseModel<String>>(baseView) {
            @Override
            public void onSuccess(BaseModel<String> o) {
                baseView.getOut03Success(o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.showError(msg);
                }
            }
        });
    }

    public void Out05(String order_sn, String type,String shelves_code, String transit_code,JSONArray items) {
        addDisposable(apiServer.Out05("2",order_sn,type, shelves_code, transit_code, items), new BaseObserver<BaseModel<String>>(baseView) {
            @Override
            public void onSuccess(BaseModel<String> o) {
                baseView.getOut03Success(o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.showError(msg);
                }
            }
        });
    }


    public void Out10(String order_type, String order_sn, JSONArray items) {
        addDisposable(apiServer.Out10(order_type, order_sn, items), new BaseObserver<BaseModel<String>>(baseView) {
            @Override
            public void onSuccess(BaseModel<String> o) {
                baseView.getOut03Success(o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.showError(msg);
                }
            }
        });
    }

    public void Out04(String serial_code) {
        addDisposable(apiServer.Out04(serial_code), new BaseObserver<BaseModel<ScanChukuBean>>(baseView) {
            @Override
            public void onSuccess(BaseModel<ScanChukuBean> o) {
                baseView.getOut04Success(o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.onError();
                }
            }
        });
    }

    public void Out06(String order_sn, String warehouse_coordinates, String transit_code,
                      String matter_code, String num) {
        addDisposable(apiServer.Out06(order_sn, warehouse_coordinates, transit_code, matter_code, num), new BaseObserver<BaseModel<ScanChukuBean>>(baseView) {
            @Override
            public void onSuccess(BaseModel<ScanChukuBean> o) {
                baseView.getOut04Success(o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.onError();
                }
            }
        });
    }
}
